﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Data;
using MyPublisher.Administration.Commands;
using System.Windows.ApplicationFramework;
using System.Collections.ObjectModel;
using MyPublisher.Administration.Model;
using MyPublisher.Framework;
using MyPublisher.Administration.Views;

namespace MyPublisher.Administration.ViewModels
{
    public class ConnectorsViewModel : DocumentViewModel<Document>
    {
        public ICommand newCommand;
        public ObservableCollection<ConnectorType> Types { get; private set; }
        public ConnectorType SelectedType { get; set; }

        public ConnectorsViewModel(IView view, string name)
            : base(view, name)
        {
            this.Types = new ObservableCollection<ConnectorType>();
            foreach (ConnectorType type in App.TypesFactory.ConnectorTypes)
            {
                this.Types.Add(type);
            }
            if (this.Types.Count > 0)
                SelectedType = this.Types[0];

            Refresh();
        }

        public ICommand NewCommand
        {
            get
            {
                if (newCommand == null)
                {
                    newCommand = new DelegateCommand(New);
                }
                return newCommand;
            }
        }

        private void New()
        {
            ConnectorType type = Types[0];
            //Connector connector = new MetaBlogConnector(App.TypesFactory,
            //    App.EntityFactory,
            //    App.EntityFactory.Locations[2],
            //    type);
            //connector.Connect();

            Refresh();
        }

        private void Refresh()
        {
            this.Items.Clear();
            this.InsertItems(App.EntityFactory.Connectors);
        }
    }
}
